package com.wf.mock.app.mina;

import org.apache.commons.lang3.StringUtils;

import com.wf.mock.app.mina.app.processor.impl.APP2PortalMessageProcessorImpl;
import com.wf.mock.app.mina.app.processor.impl.EmptyMessageProcessorImpl;
import com.wf.mock.app.mina.app.processor.impl.HeartbeatMessageProcessorImpl;
import com.wf.mock.app.mina.app.processor.impl.MinaConfirmMessageProcessorImpl;
import com.wf.mock.app.mina.app.processor.impl.Portal2APPMessageProcessorImpl;
import com.wf.mock.app.mina.app.processor.impl.SplitMsgProcessorImpl;

/**
 * 
 * @author wangyun
 * 
 */
public enum MessageIntentType {

	APPCONNECT(EmptyMessageProcessorImpl.class, "APPCONNECT"),

	APP2PORTAL(APP2PortalMessageProcessorImpl.class, "APP2PORTAL"),

	APPCONFIRM(EmptyMessageProcessorImpl.class, "APPCONFIRM"),

	PORTALCONNECT(EmptyMessageProcessorImpl.class, "PORTALCONNECT"),

	PORTAL2APP(Portal2APPMessageProcessorImpl.class, "PORTAL2APP"),

	HEARTBEAT(HeartbeatMessageProcessorImpl.class, "HEARTBEAT"),

	MINACONFIRM(MinaConfirmMessageProcessorImpl.class, "MINACONFIRM"),

	EMPTY(EmptyMessageProcessorImpl.class, "EMPTY"),

	SPLITMSGPACKET(SplitMsgProcessorImpl.class, "SPLITMSGPACKET"),

	KICKOUT(EmptyMessageProcessorImpl.class, "KICKOUT");

	private Class<?> processorClazz;

	private String preffix;

	private MessageIntentType(Class<?> processorClazz, String preffix) {
		this.processorClazz = processorClazz;
		this.preffix = preffix;
	}

	public Class<?> getProcessorClazz() {
		return processorClazz;
	}

	public String getPreffix() {
		return preffix;
	}

	/**
	 * 解析消息意向类型
	 * 
	 * @return
	 */
	public static MessageIntentType praseMessageIntentType(String msg) {

		if (StringUtils.isNotBlank(msg)) {

			MessageIntentType[] values = values();
			for (MessageIntentType type : values) {
				String typePreffix = type.getPreffix();
				if (msg.toUpperCase().startsWith(typePreffix + "{") || msg.equalsIgnoreCase(typePreffix)) {
					return type;
				}
			}
		}
		return MessageIntentType.EMPTY;
	}
}
